var addUpgradeTaskJs = function(targetObj) {
	this.targetObj = targetObj;
	this.initHtml();
	return this;
}
addUpgradeTaskJs.prototype = {

		/**
		 * 初始化界面
		 */
		initHtml : function() {
			var that = this;
			//查询工作站信息
			JsonpAjax(baseApiPath + "largeFileUpoad/findWorkingStationList",null, 'json', function(res) {
				if(isEmpty(res)) return;
				var workStationsList = that.targetObj.find("#workStationList");
				workStationsList.empty();
				var workInfo = $("<p style='font-weight:bold;cursor:pointer;'><label name='workstationName'></label><br><lable name='wkversion'></lable></p>");
				var work = null;
				var versionNo = null;
				for(var i = 0;i<res.length;i++){
					work = workInfo.clone();
					versionNo = "" == res[i]["versionNo"]?"暂无版本信息": res[i]["versionNo"];
					work.find("label[name='workstationName']").html(res[i]["orgName"]+"("+res[i]["orgCode"]+")");
					work.find("lable[name='wkversion']").html("当前版本：" + versionNo);
					work.data("json",res[i]);
					//添加点击事件
					work.bind("click",function(){
						if($(this).attr("class") == "active"){
							$(this).removeClass("active");
						}else{
							$(this).addClass("active");
						}
					});
					workStationsList.append(work);
				}
			});
			//加载版本列表
			JsonpAjax(baseApiPath + "largeFileUpoad/findVersionList",null, 'json', function(res) {
				if(isEmpty(res)) return;
				var versionList = that.targetObj.find("#versionList");
				versionList.empty();
				var versionInfo = that.targetObj.find("#templateDiv").find("div[name='versionInfo']");
				var version = null;
				//循环添加版本信息
				for(var i = 0;i<res.length;i++){
					version = versionInfo.clone();
					version.find(".updateContent").html("更新内容：" + res[i]["versionDesc"]);
					version.find("#versionNumber").html("版本号：" + res[i]["versionNumber"]);
					version.find("span[name='versionSize']").html(res[i]["fileSize"] + "(MB)");
					version.find("span[name='checkCode']").html(res[i]["checkCode"]);
					version.find("span[name='releaseTime']").html(res[i]["releaseTime"]);
					version.find("span[name='uploadUserName']").html(res[i]["uploadUserName"]);
					version.find("span[name='uploadTime']").html(res[i]["uploadTime"]);
					version.find("label[for]").attr("for","radio-1-"+i);
					version.find("input[name='radio-name']").attr("id","radio-1-"+i)
					version.data("json",res[i]);
					versionList.append(version);
				}
			});
			this.targetObj.find("#saveBtn").bind("click",this,this.saveUpgrade);
			this.targetObj.find("#cancelBtn").bind("click",closeWindow);
			//加载时间
			this.targetObj.find("#upgradeTimes").kendoDateTimePicker({
				format:"yyyy-MM-dd HH:mm:ss",
				culture:x18n.chosenLocal,
				min:new Date(),
				interval:1
			});
			var upgradeTimeDiv = this.targetObj.find("#upgradeTimeDiv");
			upgradeTimeDiv.hide();
			//选择下拉列表时触发
			var downChange = function(){
				var upgradeMethods = this.value();
				if(upgradeMethods == Utils.getModelValueByModelKey(BASIS.UPGRADE_METHODS.UPGRADE_METHODS_TIM)){
					upgradeTimeDiv.show();
					return;
				}
				upgradeTimeDiv.hide();
			};
			//加载升级方式   默认安全更新
			Utils.createDataDictDropDownList({ div: this.targetObj.find("#upgradeMethods"),change:downChange,
				parentModelKey: BASIS.UPGRADE_METHODS.ROOT,select:Utils.getModelValueByModelKey(BASIS.UPGRADE_METHODS.UPGRADE_METHODS_SEC)},this);
		},
		/**
		 * 保存版本升级信息
		 */
		saveUpgrade:function(e){
			var addTaskjs = e.data;
			//选中的版本号
			var radio = addTaskjs.targetObj.find("input[name='radio-name']:checked"); 
			if(radio.length <=0){
				notification({title : '提示', message : "请选择工作站需要升级的版本"}, 'info');
				return;
			}
			//选中的工作站
			var wkinput = addTaskjs.targetObj.find("#workStationList").find(".active");
			if(wkinput.length <=0){
				notification({title : '提示', message : "请选择至少选择一个升级的工作站"}, 'info');
				return;
			}
			//组织数据    需要增加更新方式、更新时间
			var json = new Object();
			var versionJson = radio.parents("div[name='versionInfo']").data("json");	
			json["version"] = versionJson["versionNumber"];
			var wxList = new Array();
			var pjson = null;
			wkinput.each(function(){
				pjson = $(this).data("json");
				wxList.push({orgCode:pjson["orgCode"],version:pjson["versionNo"]});
			});
			json["wxList"] = wxList;
			//更新方式
			json["updateMethod"] = addTaskjs.targetObj.find("#upgradeMethods").data("kendoDropDownList").value();
			if("" == json["updateMethod"] || null == json["updateMethod"]){
				notification({title : '提示', message : "请选择更新方式"}, 'info');
				return;
			}
			//定时更新才会有时间
			if(json["updateMethod"] == Utils.getModelValueByModelKey(BASIS.UPGRADE_METHODS.UPGRADE_METHODS_TIM)){
				var updateTime = addTaskjs.targetObj.find("#upgradeTimes").data("kendoDateTimePicker").value();
				json["updateTime"] = kendo.toString(updateTime,"yyyy-MM-dd HH:mm:ss");
				if("" == json["updateTime"] || null == json["updateTime"]){
					notification({title : '提示', message : "更新方式为定时更新时，请选择定时更新时间！！"}, 'info');
					return;
				}
			}
			//添加升级信息
			JsonpAjax(baseApiPath + "largeFileUpoad/saveUpgradeList",JSON.stringify(json), 'json', function(res) {
				closeWindow();
				ctVersionJs.findGridData();
			});
		}
}